package com.skyun.watchserer.common.models;

import com.google.gson.Gson;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by skyun on 17/8/22.
 */

public class AppInfo implements Serializable {
    public String name;

    public String packageName;

    public String version;

    public long installTime;

    public long updateTime;

    @Override
    public String toString() {
        return "应用名：" + name + "\n"
                + "包名：" + packageName + "\n"
                + "版本：" + version + "\n"
                + "安装时间：" + getInstallTime() + "\n"
                + "更新时间：" + getUpdateTime() + "\n";
    }

    public String getInstallTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(new Date(installTime));
    }

    public String getUpdateTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(new Date(updateTime));
    }

    public String toJson() {
        return new Gson().toJson(this);
    }

    public AppInfo fromJson(String json) {
        return new Gson().fromJson(json, getClass());
    }
}


